import cv2
import numpy as np


def zoomImg(img, zoom_multiple):
    height, width, channels = img.shape
    print("origin height=", height, "width=", width)
    new_height = int(height * zoom_multiple)
    new_width = int(width * zoom_multiple)
    print("new height=", new_height, "width=", new_width)
    new_image = np.zeros((new_height, new_width, channels), np.uint8)
    for i in range(new_height - 1):
        for j in range(new_width - 1):
            y = int(i/zoom_multiple)
            x = int(j/zoom_multiple)
            try:
                new_image[i, j] = img[y, x]
            except IndexError as e:
                print("i=", i, "j=", j)

    return new_image


img = cv2.imread("./GK8.png")
zoom = zoomImg(img, 3.7)#放大倍数
cv2.imshow("nearest neighbor", zoom)
cv2.imshow("image", img)
cv2.waitKey(0)
